var anydoActive = !1,
	anydoHidden = !0,
	anydoFrame = null,
	anydoButton = null,
	requestSource = null;

function createElements() {
	console.log("Creating elements...");
	anydoFrame = document.createElement("iframe");
	anydoFrame.className = "anydo";
	anydoFrame.style.width = "270px";
	anydoFrame.style.height = "100%";
	anydoFrame.style.zIndex = "2147483647";
	anydoFrame.style.position = "fixed";
	anydoFrame.style.top = "0";
	anydoFrame.style.right = "-270px";
	anydoFrame.style.display = "block";
	anydoFrame.style.boxShadow = "0 0 20px rgba(0, 0, 0, 0)";
	anydoFrame.style.border = "0";
	anydoFrame.style.webkitTransition = "right 0.3s ease-in-out, box-shadow 0.3s ease-in-out";
	document.body.appendChild(anydoFrame);
	anydoButton = document.createElement("div");
	anydoButton.className = "anydo";
	anydoButton.style.position = "fixed";
	anydoButton.style.width = "26px";
	anydoButton.style.height = "58px";
	anydoButton.style.zIndex = "2147483646";
	anydoButton.style.top = "55px";
	anydoButton.style.right = "0";
	anydoButton.style.webkitTransition = "right 0.3s ease-in-out, box-shadow 0.3s ease-in-out";
	anydoButton.style.cursor = "pointer";
	anydoButton.addEventListener("click", function() {
		toggleHidden();
		updateHidden()
	});
	document.body.appendChild(anydoButton)
}

function removeElements() {
	console.log("Removing elements...");
	document.body.removeChild(anydoFrame);
	document.body.removeChild(anydoButton);
	anydoHidden = !0;
	anydoButton = anydoFrame = null
}

function updateHidden() {
	anydoHidden ? (anydoFrame.style.right = "-270px", anydoFrame.style.boxShadow = "0 0 20px rgba(0, 0, 0, 0)", anydoButton.style.backgroundImage = "url()", anydoButton.style.right = "0") : (anydoFrame.src = requestSource, setTimeout(function() {
		anydoFrame.style.right = "0";
		anydoFrame.style.boxShadow = "0 0 20px rgba(0, 0, 0, 0.5)";
		anydoButton.style.backgroundImage = "url()";
		anydoButton.style.right = "270px"
	}, 100))
}

function toggleHidden() {
	null === anydoFrame ? console.log("toggleHidden called without frame!") : (anydoHidden = !anydoHidden, chrome.extension.sendRequest({
		action: "updateHiddenStatus",
		hidden: anydoHidden
	}))
}

function toggleActive(a) {
	console.log("Toggling... active?", anydoActive);
	anydoActive ? removeElements() : (createElements(), a || toggleHidden(), updateHidden());
	anydoActive = !anydoActive
}
chrome.extension.onRequest.addListener(function(a, b, c) {
	console.log(a, b);
	switch (a.action) {
	case "toggleTab":
		requestSource = a.src, toggleActive(a.hidden)
	}
	c()
});